package edu.lingnan.lmlibrary.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@Configuration
@EnableSwagger2 //开启Swagger2
public class SwaggerConfig {

    //配置content type
    private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES =
            new HashSet<String>(Arrays.asList("application/json","application/x-www-form-urlencoded","text/html;charset=utf-8"));


//    配置Swagger的Docket的bean实例，配置swagger-ui界面信息
    @Bean
    public Docket getDocket(){
        return new Docket(DocumentationType.SWAGGER_2).
                apiInfo(getApiInfo())
                .produces(DEFAULT_PRODUCES_AND_CONSUMES)
                .consumes(DEFAULT_PRODUCES_AND_CONSUMES)
                .select()
//                RequestHandlerSelectors：配置要扫描接口的方式，方法basePackage（），指定扫描的包名
                .apis(RequestHandlerSelectors.basePackage("edu.lingnan.lmlibrary.controller"))
                // paths:过滤的路径
//                .paths(PathSelectors.ant("/seat/get*"))
                .build();
    }
    //配置swagger信息apiInfo
    private ApiInfo getApiInfo(){
        //Contact:作者信息
        Contact contact = new Contact("lingNan", "", "");
        return new ApiInfo("LMLibrary",
                "LMLibrary预约系统",
                "1.0",
                "",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
